package com.chainyoung.component_tmtrade.ui.mvp.presenter;

import com.chainyoung.common.appcommon.entity.CommonList;
import com.chainyoung.common.appcommon.entity.UploadFile;
import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.di.scope.ActivityScope;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.common.utils.UpLoadUtils;
import com.chainyoung.component_tmtrade.bean.FiatOrder;
import com.chainyoung.component_tmtrade.bean.OrderDetail;
import com.chainyoung.component_tmtrade.ui.mvp.contract.TradeFiatCurrencyOrderContract;
import com.chainyoung.component_tmtrade.ui.mvp.contract.TradeFiatCurrencyOrderDetailContract;

import java.util.TreeMap;

import javax.inject.Inject;

import okhttp3.RequestBody;

@ActivityScope
public class TradeFiatCurrencyOrderDetailPresenter extends BasePresenter<TradeFiatCurrencyOrderDetailContract.Model, TradeFiatCurrencyOrderDetailContract.View> {


    @Inject
    public TradeFiatCurrencyOrderDetailPresenter(TradeFiatCurrencyOrderDetailContract.Model model, TradeFiatCurrencyOrderDetailContract.View rootView) {
        super(model, rootView);
    }


    public void getOrderDetail(TreeMap<String, Object> map) {
        addSubscribe(mModel.getOrderDetail(map)
                .compose(RxUtils.<OrderDetail>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<OrderDetail>(mView,true) {
                    @Override
                    public void onNext(OrderDetail data) {
                        mView.onGetOrderDetailSuccess(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        mView.onGetOrderDetailFailed();
                    }
                }));
    }

    public void cancelOrder(TreeMap<String, Object> map) {
        addSubscribe(mModel.cancelOrder(map)
                .compose(RxUtils.<String>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<String>(mView,true) {
                    @Override
                    public void onNext(String data) {
                        mView.onCancelOrderSuccess(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }

    public void confirmPayed(TreeMap<String, Object> map) {
        addSubscribe(mModel.confirmPayOrder(map)
                .compose(RxUtils.<String>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<String>(mView,true) {
                    @Override
                    public void onNext(String data) {
                        mView.onConfirmPayOrder(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }

    public void confirmRelease(TreeMap<String, Object> map) {
        addSubscribe(mModel.confirmRelease(map)
                .compose(RxUtils.<String>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<String>(mView,true) {
                    @Override
                    public void onNext(String data) {
                        mView.onConfirmRelease(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }


    public void upLoadPayImg(String path, int type) {
        RequestBody body = UpLoadUtils.getBody(path, type);
        addSubscribe(mModel.upLoadPayImg(body)
                .compose(RxUtils.<UploadFile>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<UploadFile>(mView,true) {
                    @Override
                    public void onNext(UploadFile data) {
                        mView.onUploadPayImg(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }


}
